package cur.nature.admin.dao;

import cur.nature.admin.common.config.DBAdminConfig;
import cur.nature.admin.model.po.Admin_RolePO;
import cur.nature.admin.model.vo.Admin_RoleVO;
import cur.nature.framework.mvc.crud.CrudDao;

import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import cur.nature.framework.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户角色 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-10 21:42:14
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class Admin_RoleDao extends CrudDao<Admin_RolePO, Admin_RoleVO> {
    public Admin_RoleDao(@Qualifier(DBAdminConfig.TEMPLATE) DefaultJdbcTemplate template) {
        super(Admin_RolePO.class, Admin_RoleVO.class, template);
    }

    public List<Admin_RoleVO> queryByUserId(Long userId) throws Exception {
        String sql = "select " + this.cols("a.") +
                " from " + tableName() + " a, admin_mid_user_role b " +
                " where a.id=b.role_id and b.user_id=" + userId + "";
        List<Admin_RoleVO> list = this.queryForListCust(sql,Admin_RoleVO.class);
        return list;
    }

    public List<Admin_RoleVO> queryByCond(Admin_RoleVO.list_Param param) throws Exception {
        // 过滤条件
        final StringBuilder cond = new StringBuilder();
        if (StringUtil.isNotEmpty(param.getKeyword())) {
            cond.append(" and name like '"+param.getKeyword()+"%' ");
        }
        // 查询出所有的资源
        List<Admin_RoleVO> list = queryByCond(cond.toString());
        return list;
    }

}

